const obj = {
    name: '_island',
    score:59
}
// const objProxy = new Proxy(obj,{});
// console.log(objProxy)
const objProxy = new Proxy(obj,{
    //handler 处理捕捉器
    get:function(target,key) {
        console.log(`捕获对象获取${key}属性的值操作`)
        return target[key];
    },
    // 写操作
    // 对象的访问拦截，捕捉器set
    set:function(target,key,val) {
        // target[key] = val;
        if(key=='age') {
            if(typeof val == 'number') {
                target[key] = val;
            }
            else {
                // console.warn('该值必须是number类型')
                throw new TypeError('该值必须是number类型')
            }
        }
        else{
            target[key] = val;
        }
    }
});
console.log(objProxy.name);
try {
//objProxy.age = '天山童姥' //放错
}
catch (e) {
    console.log(e);
}
console.log(objProxy.age);